package com.wlstock.funi.model;


/**
 * 
 * @author boby
 * 双向的类 包含了买入和卖出
 */
public class OpBSModel {
	
	private OperateModel buyModel;
	private OperateModel sellModel;
	
	public float totalIncome;
	public float ProfitRate;
	
	public String fundName;
	public int    fundid;
	
	public String bTradedDay;
	public String bTradedHourMinute;
	public float  bTradePrice;
	public String bStockName;
	public String bStockNo;
	
	public String sTradedDay;
	public String sTradedHourMinute;
	public float  sTradePrice;
	public String sStockName;
	public String sStockNo;
	
	public OpBSModel(){
		super();
	}

	public OperateModel getOpMode(int opType) {
		if (opType == OperateModel.TradeType_BUY) {
			return buyModel;	
		}else if (opType == OperateModel.TradeType_SELL) {
			return sellModel;
		}
		return null;
	}

	/**
	 * 传入对应的mode进行设置
	 * @param mode
	 * @param opType
	 */
	public void setOpMode(OperateModel mode, int opType) {
		if (opType == OperateModel.TradeType_BUY) {
			setBuyModel(mode);
		}else if (opType == OperateModel.TradeType_SELL) {
			setSellModel(mode);
		}
		
	}
	
	/**
	 * 是否为空仓
	 * @return
	 */
	public boolean isEmpty(){
		if (buyModel!=null) {
			return buyModel.getStockHoldDetailId()==null;
		}
		if (sellModel!=null) {
			return sellModel.getStockHoldDetailId()==null;
		}
		return true;
	}

	
	public OperateModel getBuyModel() {
		return buyModel;
	}

	public void setBuyModel(OperateModel buyModel) {
		this.buyModel = buyModel;
		if (buyModel!=null) {
			this.totalIncome = buyModel.getTotalIncome();
			this.ProfitRate = buyModel.getProfitRate();
			this.fundName  = buyModel.getFundName();
			this.fundid    = buyModel.getFundid();
			this.bTradedDay = buyModel.getTradedDay();
			this.bTradedHourMinute = buyModel.getTradedHourMinute();
			this.bTradePrice  = buyModel.getTradePrice();
			this.bStockName = buyModel.getStockName();
			this.bStockNo   = buyModel.getStockNo();
		}

	}

	public OperateModel getSellModel() {
		return sellModel;
	}

	public void setSellModel(OperateModel sellModel) {
		this.sellModel = sellModel;
		if (sellModel!=null) {
			this.totalIncome = sellModel.getTotalIncome();
			this.ProfitRate = sellModel.getProfitRate();
			this.fundName  = sellModel.getFundName();
			this.fundid    = sellModel.getFundid();
			this.sTradedDay = sellModel.getTradedDay();
			this.sTradedHourMinute = sellModel.getTradedHourMinute();
			this.sTradePrice = sellModel.getTradePrice();
			this.sStockName = sellModel.getStockName();
			this.sStockNo = sellModel.getStockNo();
		}
	}
	
	/**
	 * 返回最新操作的model
	 * @return
	 */
	public OperateModel getNewlyOPModel() {
		if (buyModel!=null && sellModel==null) {
			return buyModel;
		}
		if (buyModel==null && sellModel!=null) {
			return sellModel;
		}
		if (buyModel!=null && sellModel!=null) {
			if (buyModel.getTradedDate().after(sellModel.getTradedDate())) {
				return buyModel;
			}else {
				return sellModel;
			}
			
		}
		return null;
	}
	
	/**
	 * 返回次新的model
	 * @return
	 */
	public OperateModel getSecondOPModel() {
		
		if (getNewlyOPModel() == buyModel && sellModel!=null) {
			return sellModel;
		}else if (getNewlyOPModel() == sellModel && buyModel!=null) {
			return buyModel;
		}
		return null;
	}
	
	
}
